<template>
  <div>
    <el-form ref="param" :model="param" :rules="rules"  label-width="120px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="学校名称:" prop="schoolName">
            <el-input v-model="param.schoolName" size="mini" clearable style="width:80%"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="学校简称:" prop="schoolShortName">
            <el-input v-model="param.schoolShortName" size="mini" clearable style="width:80%"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="学校简介:" prop="schoolIntro">
           <el-input v-model="param.schoolIntro" size="mini" clearable style="width:80%"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="管理员账号:" prop="adminAccount">
           <el-input v-model="param.adminAccount" size="mini" clearable style="width:80%"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="管理员姓名:" prop="adminName">
            <el-input v-model="param.adminName" size="mini" clearable style="width:80%"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="管理员手机:" prop="adminPhone">
           <el-input v-model="param.adminPhone" size="mini" clearable style="width:80%"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="学校图标:">
            上传
          </el-form-item>
        </el-col>
        <el-col :span="12">
          
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" size="mini" @click="editor()">修改</el-button>
      <el-button @click="handCancle" size="mini">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getEdi, update } from '@/api/school/school'
export default {
  props: ['id', 'showDialog'],
  data() {
    return {
      form: {
        name: ''
      },
      value: '',
      options: [],
      param: {},
      rules: {
        shcoolName: [
          { required: true, message: '请输入学校名称', trigger: 'blur' }
        ],
        schoolShortName: [
          { required: true, message: '请输入学校简称', trigger: 'blur' }
        ],
        schoolIntro: [
          { required: true, message: '请输入学校简介', trigger: 'blur' }
        ],
        // schooIcon: [
        //   { required: true, message: '请上传学校图标', trigger: 'blur' }
        // ],
        adminAccount: [
          { required: true, message: '请输入管理员账号', trigger: 'blur' }
        ],
        adminPhone: [
           { required: true, message: '请输入管理员手机号', trigger: 'blur' },
           { pattern: /^0{0,1}(13[0-9]|15[7-9]|153|156|18[7-9])[0-9]{8}$/, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        adminName: [
           { required: true, message: '请输入管理员名称', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getEdi()
  },
  methods: {
    editor() {
      this.$refs['param'].validate((valid) => {
        if (valid) {
          update(this.param).then(res => {
            console.log(res)
            if(res.code === 200){
              this.$message.success('修改成功')
              this.$emit('handCancle', 1)
            }
          })
        } else {
          return false;
        }
      })
    },
    getEdi() {  
      getEdi(this.id).then(res => {
        console.log(res)
        this.param = res.data
      })
    },
    handCancle() {
      this.$emit('handCancle')
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    }
  },
  watch: {
      showDialog: function(n, o){
        if(n) {
          this.param.schoolId = this.id
          this.getEdi()
        }
      }
  }
}
</script>

<style scoped>
.dialog-footer{
  text-align: center;
}
.img{
  width: 40px;
  height: 40px;
}
.blod {
  font-weight: bold;
}
.flex {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-table th.gutter {
  display: table-cell !important
}
</style>
